package com.kedacom.general.genertor;


import com.kedacom.general.param.ContextParam;
import com.kedacom.general.param.MpParam;

/**
 * 代码生成执行器
 */
public class GunsExecutor {

    /**
     * 默认的生成器
     *
     *
     * @Date 2019/1/13 22:18
     */
    public static void executor(ContextParam contextParam, MpParam mpContext) {

        //执行mp的代码生成，生成entity,dao,service,model，生成后保留数据库元数据
        YunhaiMpGenerator gunsMpGenerator = new YunhaiMpGenerator(mpContext);
        gunsMpGenerator.initContext(contextParam);
        gunsMpGenerator.doGeneration();

//        //获取元数据
//        List<TableInfo> tableInfos = gunsMpGenerator.getTableInfos();
//        Map<String, Map<String, Object>> everyTableContexts = gunsMpGenerator.getEveryTableContexts();
//
//        //遍历所有表
//        for (TableInfo tableInfo : tableInfos) {
//            Map<String, Object> map = everyTableContexts.get(tableInfo.getName());
//
//            //生成控制器
//            GunsControllerGenerator gunsControllerGenerator = new GunsControllerGenerator(map);
//            gunsControllerGenerator.initContext(contextParam);
//            gunsControllerGenerator.doGeneration();
//        }
    }

    public static void main(String[] args) {

        ContextParam contextParam = new ContextParam();

        contextParam.setJdbcDriver("com.mysql.jdbc.Driver");
        contextParam.setJdbcUserName("root");
        contextParam.setJdbcPassword("root");
        contextParam.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/generator_platform?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=CTT");
        contextParam.setOutputPath("temp");
        contextParam.setAuthor("fengshuonan");
        contextParam.setProPackage("cn.stylefeng.guns.modular.test");

        MpParam mpContextParam = new MpParam();
        mpContextParam.setGeneratorInterface(true);
        mpContextParam.setIncludeTables(new String[]{"test"});
        mpContextParam.setRemoveTablePrefix(new String[]{"sys_"});

        GunsExecutor.executor(contextParam, mpContextParam);
    }

}
